project(myrender_unittest)

enable_testing()
find_package(Threads REQUIRED)
find_package(GTest CONFIG REQUIRED)

if (DEFINED ENV{GOOGLETEST_SOURCE_DIR} AND NOT "$ENV{GOOGLETEST_SOURCE_DIR}" STREQUAL "")
    file(TO_CMAKE_PATH "$ENV{GOOGLETEST_SOURCE_DIR}" GOOGLETEST_SOURCE_DIR) # convert Windows-style path to cmake path
else ()
    if (NOT "" STREQUAL "")
        message(WARNING "Using googletest src dir specified at Qt Creator wizard")
    endif ()
    set(GOOGLETEST_SOURCE_DIR "")
endif ()

if (EXISTS ${GOOGLETEST_SOURCE_DIR})
    # keep same with the actual file path
    set(GTestSrc ${GOOGLETEST_SOURCE_DIR}/googletest)
    set(GMockSrc ${GOOGLETEST_SOURCE_DIR}/googlemock)
elseif (UNIX AND EXISTS /usr/src/gtest)
    set(GTestSrc /usr/src/gtest)
    message(WARNING "Using gtest from system")
    if (EXISTS /usr/src/gmock)
        set(GMockSrc /usr/src/gmock)
    endif ()
else ()
    message( FATAL_ERROR "No googletest src dir found - set GOOGLETEST_SOURCE_DIR to enable!")
endif ()

set(GTestFiles ${GTestSrc}/src/gtest-all.cc)
set(GTestIncludes ${GTestSrc} ${GTestSrc}/include)
if (NOT ${GMockSrc} STREQUAL "")
    list(APPEND GTestFiles ${GMockSrc}/src/gmock-all.cc)
    list(APPEND GTestIncludes ${GMockSrc} ${GMockSrc}/include)
endif ()

include_directories(${GTestIncludes})

add_executable(${PROJECT_NAME} main.cpp
               ${GTestFiles}
               mathengine_unittest.cpp
               tagimage_unittest.cpp
               transform_unittest.cpp
               # objfile_unittest.cpp
           )
add_test(NAME mytest COMMAND ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Core Threads::Threads libmyrender)
